package cn.kongwg.demo1;

import java.lang.reflect.Constructor;

/**
 * @author kongwg
 * @create 2021-05-19 17:22
 */
class Person{
    private static volatile Person person;
    private Person(){
        System.out.println(Thread.currentThread().getName());
    }

    public static final Person getPersonInstance(){
        if (person == null) {
            synchronized (Person.class) {
                if (person == null){
                    person = new Person();
                    return person;
                }
            }
        }
        return person;
    }
}


public class LanDemo {
    public static void main(String[] args) throws  Exception{
//        for (int i = 0; i < 10; i++) {
//            new Thread(() -> {
//            Person.getPersonInstance();
//            }).start();
//        }

//
//        Constructor<Person> constructor = Person.class.getDeclaredConstructor(null);
//        constructor.setAccessible(true);
//        Person person = constructor.newInstance();
//        Person person1 = constructor.newInstance();
//        System.out.println("person1 = " + person1);
//        System.out.println("person = " + person);


        Constructor<Myenum> constructor = Myenum.class.getDeclaredConstructor(String.class,int.class);
        constructor.setAccessible(true);
        Myenum myenum = constructor.newInstance();
        Myenum myenum1 = constructor.newInstance();
        System.out.println("myenum = " + myenum);
        System.out.println("myenum1 = " + myenum1);
    }

}
